#include "MarbleTexture.h"

MarbleTexture::MarbleTexture(float stripes_per_unit, float _scale /* = 5.0f */, int _octaves /* = 8 */)
	: scale(_scale), octave(_octaves)
{
	freq = PI * stripes_per_unit;
	c0 = rgb(0.8f, 0.8f, 0.8f);
	c1 = rgb(0.4f, 0.2f, 0.1f);
	c2 = rgb(0.06f, 0.04f, 0.02f);
}

MarbleTexture::MarbleTexture(const rgb& _c0, const rgb& _c1, const rgb& _c2,
	float stripes_per_unit, float _scale /* = 3.0f */, int _octaves /* = 8 */)
	: c0(_c0), c1(_c1), c2(_c2), scale(_scale), octave(_octaves)
{
	freq = PI * stripes_per_unit;
	
}

rgb MarbleTexture::value(const Vector2& uv, const Vector3& p) const
{
	float temp = scale * noise.turbulence(freq * p, octave);
	float t = 2.0f * fabs(sin(freq * p.x() + temp));

	if (t < 1.0f)
		return c1 * t + (1.0f - t) * c2;
	else
	{
		t -= 1.0f;
		return c0 * t + (1.0f - t) * c1;
	}
}